var express = require('express');
var router = express.Router();
const productService = require('../service/productService');

router.get('/',async function(req,res){
    let {type,value,current,size,callback} = req.query;
    let searchObj = {};
    let data = await productService.find(searchObj
            ,{current:current||1,size:size||5});
    res.send(data);
});
router.get('/all',async function(req,res){
    let data = await productService.findAll();
    console.log('data',data);
    res.send(data);
});
router.get('/:id',async function(req,res){
    let id = req.params.id;
    let data = await productService.findById(id);
    res.send(data);
});

router.post('/',async function(req,res){
    let data = await productService.insert(req.body);
    res.send(data);
});
router.put('/:id',async function(req,res){
    let id = req.params.id;
    let data = await productService.update(id,req.body);
    res.send(data);
});
router.delete('/:id',async function(req,res){
    let data = await productService.delete(req.params.id);
    res.send(data);
})

module.exports = router;